/*
 * Copyright (C) 2015 Realtek Semiconductor Corp.
 * All Rights Reserved.
 *
 * This program is the proprietary software of Realtek Semiconductor
 * Corporation and/or its licensors, and only be used, duplicated,
 * modified or distributed under the authorized license from Realtek.
 *
 * ANY USE OF THE SOFTWARE OTHER THAN AS AUTHORIZED UNDER
 * THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
 *
 * Purpose : OMCI driver feature module
 *
 * Feature : Force DS bridge untagged
 */

/*
 * Include Files
 */
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <DRV/omci_drv.h>

/*
 * Data Declaration
 */

/*
 * Function Declaration
 */
static unsigned int iphost_from_filter(va_list argp)
{
    OMCI_BRIDGE_RULE_ts *pNew;
    OMCI_BRIDGE_RULE_ts *pCur;

    pNew       = va_arg(argp, OMCI_BRIDGE_RULE_ts *);
    pCur       = va_arg(argp, OMCI_BRIDGE_RULE_ts *);
    va_end(argp);


    if (!pNew || !pCur)
        return OMCI_ERR_FAILED;
    
    memcpy(pNew, pCur, sizeof(OMCI_BRIDGE_RULE_ts));
    
    //for some corner case: TBD
    //like omcidrv_IpHostToVeIpRule
    
    return OMCIDRV_FEATURE_ERR_OK;
}

static feature_kapi_t feature_api_entry =
{
    .regApiId       = FEATURE_KAPI_RDP_00000020,
    .regCB          = iphost_from_filter,
    .regModuleName  = "omci_iphost_from_filter",
};

int __init omci_iphost_from_filter_init(void)
{
	if (OMCIDRV_FEATURE_ERR_OK != omcidrv_feature_register(&feature_api_entry))
    {
        printk("%s() init failed\n", __FUNCTION__);

        return -1;
    }

	return 0;
}

void __exit omci_iphost_from_filter_exit(void)
{
    feature_kapi_t  entry;

    memset(&entry, 0, sizeof(feature_kapi_t));
    entry.regApiId = FEATURE_KAPI_RDP_00000020;
    entry.regCB = NULL;

	if (OMCIDRV_FEATURE_ERR_OK != omcidrv_feature_unregister(&entry))
    {
        printk("%s() exit failed\n", __FUNCTION__);
    }
}

/*
 * Symbol Definition
 */

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("RealTek OMCI kernel module");
MODULE_AUTHOR("RealTek");
module_init(omci_iphost_from_filter_init);
module_exit(omci_iphost_from_filter_exit);
